package jy.game.components.wuxue.box;

import java.util.ArrayList;
import java.util.List;

import jy.game.components.wuxue.JyTrigger;
import jy.game.components.wuxue.SkillCoverType;
import jy.game.components.wuxue.SkillType0;
import jy.game.components.wuxue.pojo.JyInternalSkill;
import jy.game.components.wuxue.pojo.JyUniqueSkill;
import jy.game.tools.CommonSettings;
import jy.game.tools.JyResourceManager;
import wx.xml.simpleframework.xml.Attribute;
import wx.xml.simpleframework.xml.Root;


@Root(name = "internal_skill")
public class JyInternalSkillInstance extends JySkillBox {
    @Attribute public int    level;
    @Attribute public int    exp;
    @Attribute public String name;

    //[XmlIgnore]
    public List<UniqueSkillInstance> uniqueSkills = new ArrayList<>();

//    public JyInternalSkillInstance(String name, int level, int exp, int equipped) {
//        this.name = name;
//        this.exp = exp;
//        this.level = level;
//        this.equipped = equipped;
//    }

    // (get) Token: 0x060004F2 RID: 1266 RVA: 0x00004A59 File Offset: 0x00002C59
    // (set) Token: 0x060004F3 RID: 1267 RVA: 0x00004A61 File Offset: 0x00002C61


//    public void refreshUniqueSkills() {
//        this.uniqueSkills.clear();
//        for (JyUniqueSkill skill : this.internalSkill().uniqueSkills) {
//            this.uniqueSkills.add(new UniqueSkillInstance(skill, this));
//        }
//    }

    // (get) Token: 0x060004F5 RID: 1269 RVA: 0x00032618 File Offset: 0x00030818
    public int yin() {
        {
            if (CommonSettings.MOD_KEY == 1) {
                int num = this.internalSkill().yin * this.level() / 10;
                if (owner != null) {
                    if (owner.HasTalent("阴阳合一")) {
                        num = (int) (num * 1.4);
                    } else if (owner.HasTalent("九阴归一")) {
                        num = (int) (num * 1.4);
                    }
                    if (owner.HasTalent("寒冰")) {
                        num = (int) (num * 1.03);
                    }
                }
                return num;
            }
            return this.internalSkill().yin * this.level() / 10;
        }
    }

    // (get) Token: 0x060004F6 RID: 1270 RVA: 0x000326C8 File Offset: 0x000308C8
    public int yang() {
        int num = this.internalSkill().yang * this.level() / 10;
        if (owner != null && owner.HasTalent("至刚至阳")) {
            num = (int) (num * 1.3);
        }
        if (CommonSettings.MOD_KEY == 1 && owner != null) {
            if (owner.HasTalent("阴阳合一")) {
                num = (int) (num * 1.4);
            } else if (owner.HasTalent("九阳归一")) {
                num = (int) (num * 1.4);
            }
            if (owner.HasTalent("烈火")) {
                num = (int) (num * 1.03);
            }
        }
        return num;

    }

    // (get) Token: 0x060004F7 RID: 1271 RVA: 0x00032788 File Offset: 0x00030988
    public double attack() {
        double num = 1f;
        if (owner != null) {
            for (JyTrigger trigger : owner.GetTriggers("powerup_internalskill")) {
                if (trigger.Argvs()[0].equals(this.internalSkill().name)) {
                    num += (double) (Integer.parseInt(trigger.Argvs()[1]) / 100.0);
                }
            }
        }
        return level() / 10f * this.internalSkill().attack * num;
    }

    // (get) Token: 0x060004F8 RID: 1272 RVA: 0x00004A6A File Offset: 0x00002C6A
    public double critical() {
        if (this.level() < 10) {
            return level() / 10f * this.internalSkill().critical;
        }
        return this.internalSkill().critical;
    }


    // (get) Token: 0x060004FD RID: 1277 RVA: 0x00004AC1 File Offset: 0x00002CC1
//    public /*override*/ Color Color() {
//        {
//            return Color.magenta;
//        }
//    }

    // (get) Token: 0x060004F9 RID: 1273 RVA: 0x00032850 File Offset: 0x00030A50
    public double defence() {
        double num = 1f;
        if (owner != null) {
            for (JyTrigger trigger : owner.GetTriggers("powerup_internalskill")) {
                if (trigger.Argvs()[0] == this.internalSkill().name) {
                    num += (double) (Integer.parseInt(trigger.Argvs()[1]) / 100.0);
                }
            }
        }
        return this.level() / 10f * this.internalSkill().defence * num;
    }

    // (get) Token: 0x060004FA RID: 1274 RVA: 0x00004A9E File Offset: 0x00002C9E
    public double hard() {
        return this.internalSkill().hard;
    }

    // (get) Token: 0x060004FB RID: 1275 RVA: 0x00004AAC File Offset: 0x00002CAC
    public /*override*/ String Name() {
        return this.name;
    }

    // (get) Token: 0x060004FC RID: 1276 RVA: 0x00004AB4 File Offset: 0x00002CB4
    public /*override*/ String icon() {
        return this.internalSkill().icon;
    }

    // (get) Token: 0x060004FE RID: 1278 RVA: 0x00003D5C File Offset: 0x00001F5C
    public /*override*/ int coolDown() {
        return 0;
    }

    // (get) Token: 0x060004FF RID: 1279 RVA: 0x00004AC8 File Offset: 0x00002CC8
    public /*override*/ int Type() {
        return 4;
    }

    // (get) Token: 0x06000500 RID: 1280 RVA: 0x00032918 File Offset: 0x00030B18
    public /*override*/ int costMp() {
        return (int) this.hard() * this.level() * 4;
    }

    // (get) Token: 0x06000501 RID: 1281 RVA: 0x00004ACB File Offset: 0x00002CCB
    @Override public /*override*/ double power() {
        return this.attack() * 13f;
    }


    // (get) Token: 0x06000502 RID: 1282 RVA: 0x00003D5C File Offset: 0x00001F5C
    public /*override*/ int costBall() {
        return 0;
    }


    // (get) Token: 0x06000503 RID: 1283 RVA: 0x00003D5C File Offset: 0x00001F5C
    public /*override*/ int castSize() {
        return 0;
    }

    // (get) Token: 0x06000504 RID: 1284 RVA: 0x00003D5C File Offset: 0x00001F5C
    public /*override*/ int size() {
        return 0;
    }


    // (get) Token: 0x06000509 RID: 1289 RVA: 0x00032938 File Offset: 0x00030B38
    //[XmlIgnore]
    //public /*override*/ String descriptionInRichtext {
    //    get {
    //        return getDescriptionInRichtext(false);
    //    }
    //}

//    protected /*override*/ String getDescriptionInRichtext(boolean forAchievement) {
//        String text = "";
//        text += this.internalSkill().info;
//        text += "\n";
//        if (forAchievement) {
//            text += String.format("<color='black'>等级 %s/%s</color>\n", this.maxLevel, CommonSettings.MAX_INTERNALSKILL_LEVEL);
//        } else {
//            text += String.format("<color='black'>等级 %s/%s</color>\n", this.level, this.maxLevel);
//        }
//        text += String.format("<color='black'>经验 %s/%s</color>\n", this.exp, this.levelupExp);
//        text += String.format("<color='red'>+攻击 %s%%</color>\n", this.attack * 100f);
//        text += String.format("<color='green'>+防御 %s%%</color>\n", this.defence * 100f);
//        text += String.format("<color='yellow'>+爆发 %s%%</color>\n", this.critical * 100f);
//        text += String.format("<color='cyan'>阴适性 %s</color>\n", this.yin);
//        text += String.format("<color='yellow'>阳适性 %s</color>\n", this.yang);
//        if (this.internalSkill().triggers.Count > 0) {
//            text += "\n 被动增益：\n";
//            for (JyTrigger trigger : this.internalSkill().triggers) {
//                if (this.level < trigger.level) {
//                    if (trigger.level <= this.maxLevel) {
//                        text += String.format("<color='red'>(×)(%s级解锁)%s</color>", trigger.toString(), trigger.level);
//                    } else {
//                        text += String.format("<color='red'>(×)(%s级解锁)???</color>", trigger.level);
//                    }
//                } else {
//                    text += String.format("<color='green'>(√)(%s级解锁)%s</color>", trigger.toString(), trigger.level);
//                }
//                text += "\n";
//            }
//        }
//        return text;
//    }

    // (get) Token: 0x06000505 RID: 1285 RVA: 0x00003D5C File Offset: 0x00001F5C
    public /*override*/ SkillCoverType coverType() {
        return SkillCoverType.NORMAL;
    }

    // (get) Token: 0x06000506 RID: 1286 RVA: 0x00004AD9 File Offset: 0x00002CD9
    public /*override*/ String animation() {
        return null;
    }

    // (get) Token: 0x06000507 RID: 1287 RVA: 0x00003D59 File Offset: 0x00001F59
    public /*override*/ SkillType0 skillType() {
        return SkillType0.Internal;
    }

    // (get) Token: 0x06000508 RID: 1288 RVA: 0x00004ADC File Offset: 0x00002CDC
    @Override public /*override*/ int level() {
        return this.level;
    }

    // (get) Token: 0x0600050A RID: 1290 RVA: 0x00004AE4 File Offset: 0x00002CE4
    //[XmlIgnore]
    public int levelupExp() {
        return this.getLevelupExp(this.level());
    }

    public int getLevelupExp(int currentLevel) {
        return (int) ((currentLevel + 4f) / 4f * (this.hard() + 4f) / 4f * 40f);
    }

    // (get) Token: 0x0600050C RID: 1292 RVA: 0x00004B1C File Offset: 0x00002D1C
    public JyInternalSkill internalSkill() {
        return JyResourceManager.get(JyInternalSkill.class, this.name);
    }

    public boolean hasTalent(String talent) {
        return this.talents().contains(talent);
    }

    // (get) Token: 0x0600050E RID: 1294 RVA: 0x00032B5C File Offset: 0x00030D5C
    //[XmlIgnore]
    public List<String> talents() {
        {
            List<String> talents = new ArrayList<>();
            for (JyTrigger t : this.internalSkill().triggers) {
                if (t.name == "eq_talent" && this.level() >= t.level && this.isUsed()) {
                    talents.add(t.Argvs()[0]);
                }
                if (t.name == "talent" && this.level() >= t.level) {
                    talents.add(t.Argvs()[0]);
                }
            }
            return talents;
        }
    }

    @Override public /*override*/ boolean tryAddExp(int exp, int maxLevel) {
        exp += owner.AttributesFinal.get("wuxing") / 30;
        if (owner.HasTalent("武学奇才")) {
            this.exp += exp * 2;
        } else {
            this.exp += exp;
        }
        this.exp += exp;
        boolean flag = false;
        if (maxLevel < 1) {
            maxLevel = this.maxLevel();
        } else {
            maxLevel = Math.min(maxLevel, CommonSettings.MAX_INTERNALSKILL_LEVEL);
        }
        while (this.exp >= this.levelupExp()) {
            if (this.level() >= maxLevel) {
                this.exp = this.levelupExp();
                break;
            }
            this.exp -= this.levelupExp();
            this.level++;
            if (this.level > CommonSettings.MAX_INTERNALSKILL_LEVEL) {
                this.level = CommonSettings.MAX_INTERNALSKILL_LEVEL;
            }
            flag = true;
        }
        if (flag) {
            // RuntimeData.Instance.RefreshTeamMemberPanel(owner.key, false, true);
        }
        return flag;
    }

    public void SetLevel(int level) {
        this.level = level;
    }
}